package cn.dgut.jy.soro.service.impl;

import cn.dgut.jy.soro.entity.Appointment;
import cn.dgut.jy.soro.repository.AppointmentRepository;
import cn.dgut.jy.soro.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class AppointmentServiceImpl implements AppointmentService {

    private AppointmentRepository appointmentRepository;

    @Autowired
    public AppointmentServiceImpl(AppointmentRepository appointmentRepository) {
        this.appointmentRepository = appointmentRepository;
    }

    @Override
    public void addAppointment(Integer userId, String petType, String contentType,
                               String address, String store, String name,
                               Date date, String demand) {
        Appointment appointment = new Appointment();
        appointment.setUserId(userId);
        appointment.setPetType(petType);
        appointment.setContentType(contentType);
        appointment.setAddress(address);
        appointment.setStore(store);
        appointment.setName(name);
        appointment.setDate(date);
        appointment.setDemand(demand);

        appointmentRepository.save(appointment);
    }

    @Override
    public List<Appointment> getAppointments(Integer userId) {
        return appointmentRepository.findByUserId(userId);
    }

    @Override
    public List<Appointment> getAllAppointments() {
        return appointmentRepository.findAll();
    }
}
